function plot_dvf_psuedo_cdf_toolbox(patient, scan)


scan_folder = [patient.model_folder '/Psuedo_scans' sprintf('/scan%d',scan)];
dvf_pseudo = metaImageRead([scan_folder sprintf('/Registration/deformationField')]);
dvf_vec = bsxfun(@hypot, squeeze(dvf_pseudo(:,:,1,:)), bsxfun(@hypot, squeeze(dvf_pseudo(:,:,2,:)),squeeze(dvf_pseudo(:,:,3,:))));
dvf_folder_original = [patient.folder_elastix sprintf('/out_phase%d_phase%d',patient.ref, scan)];
dvf_original =  metaImageRead([dvf_folder_original '/deformationField']);
dvf_original_vec = bsxfun(@hypot, squeeze(dvf_original(:,:,1,:)), bsxfun(@hypot, squeeze(dvf_original(:,:,2,:)),squeeze(dvf_original(:,:,3,:))));

mask = metaImageRead([scan_folder sprintf('/pseudo_mask%d', scan)]);
X = dvf_vec(mask>0);
X_orig = dvf_original_vec(mask>0);

%
p1 = cdfplot(X);
title(sprintf('Psuedo Scan %d vs Scan %d', scan, scan))

xlabel('Error [mm]');
ylabel('Empirical CDF');

xlim([0 max(X)])
set(p1,'linewidth',2);
hold on;
mean_vec = nanmean(X);
% nanstd(dvf_2_vec(patient.static_mask>0))
vec_95 = prctile(X, 95);
p2 = plot([mean_vec mean_vec],[0 1], 'r--', 'LineWidth', 2);
p3 = plot([vec_95 vec_95], [0 1], 'k--','LineWidth', 2);
legend([p2(1,1), p3(1,1)], sprintf('Mean = %.2f mm', mean_vec), sprintf('95th %%^{ile} = %.2f mm', vec_95),'Location', 'SE')
    N=15
    set(gca,'FontSize',15)
    h_xlabel = get(gca,'XLabel');
    set(h_xlabel,'FontSize',N);
    h_ylabel = get(gca,'YLabel');
    set(h_ylabel,'FontSize',N);
hold off
